//新开就诊后台
import Mock from 'mockjs'
import { param2Obj } from '../utils/urlutils.js'

var list = []

for (var i = 0; i < 50; i++) {
    list.push({
        name: Mock.mock('@ctitle(3, 5)'),
        total: Mock.mock('@natural(1, 3)'),
        price: Mock.mock('@natural(500, 1000)'),
        frequency: Mock.mock('@natural(1, 2)'),
    })
}

const tablelist = []
for (var i = 0; i < 30; i++) {
    tablelist.push({
        id: i + 1,
        groupnumber: Mock.mock('@natural(1, 5)'),
        name: Mock.mock('@ctitle(3, 5)'),
        once: Mock.mock('@natural(1, 3)'),
        frequency: Mock.mock('@natural(1, 3)'),
        total: Mock.mock('@natural(1, 5)'),
        date: Mock.mock('@natural(1, 3)'),
        price: Mock.mock('@natural(20, 100)'),
    })
}
console.log(tablelist);
export default {
    getNewvisitData(config) {
        console.log('config', param2Obj(config.url));
        var { keywords } = param2Obj(config.url);
        var arr = list.filter(item => {
            return item.name.indexOf(keywords) != -1
        });
        console.log(arr);
        return {
            code: 200,
            msg: '获取成功',
            data: arr
        }
    },
    getMytableData(config) {
        return {
            code: 200,
            msg: '获取成功111',
            data: tablelist
        }
    },
    addData(config) {
        console.log(config.body);
        var obj = JSON.parse(config.body);
        console.log(obj);
        obj.id = Mock.mock('@natural(1, 3)')
        obj.groupnumber = Mock.mock('@natural(1, 5)')
        obj.once = Mock.mock('@natural(1, 3)')
        obj.date = Mock.mock('@natural(1, 3)')
        tablelist.unshift(obj)
        return {
            code: 200,
            msg: '添加成功',
            data: null
        }
    }

}
